package me.shiqiang.im.listeners;

import me.shiqiang.im.enums.MessageCmd;
import me.shiqiang.im.msg.SyncFriendResp;
import me.shiqiang.im.service.OptService;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author cuishiqiang
 * @date 2018/1/12 下午10:57
 */
@Component("FriendReqListener")
public class FriendReqListener extends ConnectServerListener {
    @Override
    public String eventName() {
        return MessageCmd.SYNC_FRIEND_REQ;
    }

    @Autowired
    OptService optService;

//    @Autowired
//    Socket socket;

    @Override
    public void call(Object... objects) {
        JSONObject obj = (JSONObject)objects[0];
        SyncFriendResp resp = optService.processFriendSyncReq(obj.getLong("userId"));
        socket.emit(MessageCmd.SYNC_FRIEND_RESP, JSONObject.wrap(resp));
    }
}
